/**
 * Copyright (C) 2016 Eshore Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.eshore.thrpc.heartbeat;

import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.eshore.thrpc.common.ServerNode;
import com.google.common.collect.Sets;

/**
 * 
 * 服务主机集合
 * 
 *   
 * @author zhouzhixiang  
 * @date 2016年12月20日 下午6:06:09 
 * @since 1.0
 */
public class DynamicHostSet {

    /** LOGGER */
    private final Logger LOGGER = LoggerFactory.getLogger(getClass());

    /** 所有的{@link ServerNode} */
    private final Set<ServerNode> all = Sets.newHashSet();


    /**
     * add a server instance.
     * 
     * @param serverNode
     *            {@link ServerNode}
     */
    public synchronized void addServerInstance(ServerNode serverNode) {
        if (!all.contains(serverNode)) {
            LOGGER.warn("add {} to all set", serverNode);
            all.add(serverNode);
        }
    }
    
    /**
     * getter method
     * 
     * @see DynamicHostSet#all
     * @return the all
     */
    public Set<ServerNode> getAll() {
        return all;
    }

    @Override
    public String toString() {
        return "DynamicHostSet [all=" + all + "]";
    }
    
    
}
